<?php

namespace app\backend\controller;

use app\backend\service\CashService;

class Cash extends Backend
{
    /**
     * 提现记录
     * @param CashService $service
     * @return string|\think\response\Json
     * @throws \app\common\RootException
     * @throws \think\db\exception\DbException
     */
    public function index(CashService $service)
    {
        if ($this->request->isAjax()) {
            return $this->success($service->lists($this->request->param()));
        }
        return $this->fetch('', $service->labelData());
    }

    /**
     * 打款审核
     * @param CashService $service
     * @return string|\think\response\Json
     * @throws \app\common\RootException
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function edit(CashService $service)
    {
        $params = $this->request->param();
        if ($this->request->isAjax()) {
            return $this->success($service->edit($params));
        }
        $fetchData = $service->labelData();
        $fetchData['info'] = $service->detail($params['id']);
        unset($fetchData['stateLabel'][1], $fetchData['stateLabel'][3]);
        return $this->fetch('', $fetchData);
    }

    /**
     * 提现详情
     * @param CashService $service
     * @return string
     * @throws \app\common\RootException
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function detail(CashService $service)
    {
        $fetchData = $service->labelData();
        $fetchData['info'] = $service->detail($this->request->param('id'));
        return $this->fetch('', $fetchData);
    }
}